<?php
/* 
* @Author: LDF QQ 47121862
* @Date:   2014-05-14 12:37:58
* @Last Modified by:   LDF QQ 47121862
* @Last Modified time: 2014-05-15 11:20:13
*/
Class GoodsAttrControl extends AuthControl{
	private $attrClass; //属性类型
	public function __auto(){
		$this->attrClass = K('attrClass');
	}
	//商品属性列表
	public function index(){
		$gtid=Q('gtid',0,'intval');
		$this->data = $this->attrClass->where(array('gtid'=>$gtid))->all();
		$this->display();
	}
	//添加商品属性
	public function add(){
		if(IS_POST){
			if($this->attrClass->addAttrClass()){
				$this->success('添加商品属性成功...',U('index',array('gtid'=>Q('gtid'))));
			}else{
				$this->error($this->attrClass->error,U('add',array('gtid'=>Q('gtid'))));
			}
		}else{
			$this->display();
		}
	}
	//修改商品属性
	public function edit(){
		if(IS_POST){
			if($this->attrClass->saveAttrClass()){
				$this->success('修改属性成功...');
			}else{
				$this->error($this->attrClass->error);
			}
		}else{
			//获取属性值模板
			$cdata=$this->attrClass->find(Q('acid',0,'intval'));
			$this->vtpl = APP_PATH.'Field/'.$cdata['show_type'].'/edit.php'; //分配模板
			$this->avdata=M('attr_value')->where(array('acid'=>Q('acid',0,'intval')))->all();
			$this->cdata=$cdata;
			$this->display();
		}
	}
	//删除属性
	public function del(){
		if($this->attrClass->delAttrClass()){
			$this->success('删除成功....');
		}else{
			$this->error($this->attrClass->error);
		}
	}

	//添加属性类型 获得inpu select 模板
	public function addAttr(){
		$type = $_POST['type'];
		$path = APP_PATH . 'Field/' . $type . '/add.php';
		$c = $this->fetch($path);
		echo $c;die;
	}
}
